package com.a.learning_keep.util

import android.app.TimePickerDialog
import android.content.Context
import android.graphics.drawable.GradientDrawable
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat


/**
 * 创建一个弹窗
 * */
fun showCustomDialog(context: Context, string: String, function: () -> Unit) {
    val builder = AlertDialog.Builder(context)
    builder.setTitle("提示")
    builder.setMessage(string)

    builder.setPositiveButton("确定") { dialog, _ ->
        dialog.dismiss() // 关闭弹窗
        function()
    }
    val dialog: AlertDialog = builder.create()
    dialog.show()
}

/**
 * 渐变色
 * */
fun gradient(v: View, context: Context, color_name: Int, color_name2: Int) {
    // 创建一个GradientDrawable对象
    val gradientDrawable = GradientDrawable()
    // 设置渐变色数组
    val colors = intArrayOf(
        ContextCompat.getColor(context, color_name),
        ContextCompat.getColor(context, color_name2)
    )
    gradientDrawable.colors = colors
    // 设置渐变方向，这里是从上到下的渐变
    gradientDrawable.gradientType = GradientDrawable.LINEAR_GRADIENT
    gradientDrawable.orientation = GradientDrawable.Orientation.TOP_BOTTOM
    // 将GradientDrawable对象应用到View上
    v.background = gradientDrawable
}


